package org.example.rabbitmqtest.listener;

import org.example.rabbitmqtest.entity.User;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component  //注册为Bean
public class TestListener {

//    @RabbitListener(queues = "dl_queue", messageConverter = "jacksonConverter")   //定义此方法为队列testQueue2的监听器，一旦监听到新的消息，就会接受并处理
//    public void test(User user){
//        System.out.println(user);
//    }

//    //工作队列模式
//    @RabbitListener(queues = "testQueue", containerFactory = "listenerContainer")
//    public void receive(String message) throws InterruptedException {
//        System.out.println("一号消息队列监听器:" + message);
//        Thread.sleep(200);
//    }
//
//    @RabbitListener(queues = "testQueue", containerFactory = "listenerContainer")
//    public void receive2(String message) throws InterruptedException {
//        System.out.println("二号消息队列监听器:" + message);
//        Thread.sleep(200);
//    }

//    //发布订阅模式
//    @RabbitListener(queues = "yyds1")
//    public void receiver(String data){
//        System.out.println("一号消息队列监听器 "+data);
//    }
//
//    @RabbitListener(queues = "yyds2")
//    public void receiver2(String data){
//        System.out.println("二号消息队列监听器 "+data);
//    }

//    //主题模式
//    @RabbitListener(queues = "yyds")
//    public void receive(String data){
//        System.out.println("消息队列监听器: "+data);
//    }

}